<template>
  <!--角色权限-->
  <div class="rolePermission">
    <el-row>
      <el-form
        ref="ruleForm"
        label-width="80px"
        :model="queryParams"
      >
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="角色名称">
              <el-input v-model="queryParams.role" placeholder="搜索关键字"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6" align="left">
            <el-form-item label="角色编号">
              <el-input v-model="queryParams.roleCode" placeholder="搜索关键字"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12" align="right">
            <div style="padding-bottom: 20px">
              <el-button type="primary" icon="el-icon-search" size="small">筛选</el-button>
              <el-button icon="el-icon-refresh" size="small">重置</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </el-row>
    <el-row style="margin: 0 0 15px 0">
      <el-button type="primary" plain @click="handleClick({name:'角色权限',value:'rolexj'})">新建</el-button>
      <el-button type="primary" plain @click="updateClick">修改</el-button>
      <el-button type="primary" plain @click="toDelete">删除</el-button>
    </el-row>
    <el-row>
      <el-table
        ref="table"
        v-loading="loading"
        :data="tableData"
        :header-cell-style="{backgroundColor: '#e7f6f3'}"
        @row-click="(row)=>{handleClick({name: '角色权限', value: 'roleck', row: row})}"
        @selection-change="selectionChange"
        style="width: 100%">
        <el-table-column type="selection" width="55" fixed="left"></el-table-column>
        <el-table-column prop="number" label="编号"></el-table-column>
        <el-table-column prop="characterName" label="角色名称"></el-table-column>
        <el-table-column prop="add" label="新增"></el-table-column>
        <el-table-column prop="update" label="修改"></el-table-column>
        <el-table-column prop="save" label="保存"></el-table-column>
        <el-table-column prop="delete" label="删除"></el-table-column>
        <el-table-column prop="upgrade" label="升级"></el-table-column>
        <el-table-column prop="demotion" label="降级"></el-table-column>
        <el-table-column prop="lead" label="导入"></el-table-column>
        <el-table-column prop="export" label="导出"></el-table-column>
        <el-table-column prop="print" label="打印"></el-table-column>
        <el-table-column prop="projectkalender" label="项目日历"></el-table-column>
        <el-table-column prop="maintenanceTask" label="维护任务"></el-table-column>
        <el-table-column prop="book" label="查看任务"></el-table-column>
      </el-table>
      <pagination v-show="total>0" :total="total" :page.sync="pageNum" :limit.sync="pageSize"
                  style="margin: 0 25px 28px;"/>
    </el-row>
    <el-dialog :title="modalTitle" :visible.sync="modalState" @close="closeModal" :width="modalWidth"
               :close-on-click-modal="false">
      <quick-dialog :modalRow="modalRow" v-if="modalStatus!='del'"></quick-dialog>
      <div v-if="modalStatus=='del'"><span>该操作不能恢复，是否进行删除操作</span></div>
      <div v-if="modalStatus=='del'" slot="footer">
        <el-button @click="closeModal">取 消</el-button>
        <el-button type="primary" @click="closeModal">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import QuickDialog from "@/views/leader/components/quickDialog";

export default {
  name: "rolePermission",
  components: {QuickDialog},
  data() {
    return {
      loading: false,
      modalTitle: '',
      modalState: false,
      modalStatus: '',
      modalWidth: '',
      total: 0,
      tableData: [
        {
          number: '001',
          characterName: '项目负责人',
          add: '勾选',
          update: '勾选',
          save: '勾选',
          delete: '勾选',
          upgrade: '勾选',
          demotion: '勾选',
          lead: '勾选',
          export: '勾选',
          print: '勾选',
          projectkalender: '勾选',
          maintenanceTask: '全部任务',
          book: '全部任务'
        },
        {
          number: '002',
          characterName: '项目成员',
          add: '勾选',
          update: '勾选',
          save: '勾选',
          delete: '勾选',
          upgrade: '勾选',
          demotion: '勾选',
          lead: '勾选',
          export: '未勾选',
          print: '未勾选',
          projectkalender: '未勾选',
          maintenanceTask: '负责和参与任务',
          book: '全部任务'
        },
      ],
      pageNum: 1,
      pageSize: 10,
      queryParams: {
        roleCode: '',
        role: ''
      },
      modalPic: '',
      modalRow:{},
      selection:[]
    }
  },
  mounted() {
    this.total = this.tableData.length
  },
  methods: {
    closeModal() {
      this.modalState = false
    },
    //修改
    updateClick(){
      if(this.selection.length===0){
        this.$modal.msg('请选择一条修改数据');
      }else{
        this.modalState = true
        this.modalWidth = '60%'
        this.modalStatus = ''
        this.modalTitle = ''
        this.modalRow = {
          name:'角色权限',
          value:'rolexj',
          row: this.selection[0]
        }
        console.log(this.modalRow)
      }
    },
    //新增/选中列表-行
    handleClick(data) {
      this.modalState = true
      this.modalWidth = '60%'
      this.modalStatus = ''
      this.modalTitle = ''
      this.modalRow = data
    },
    //删除
    toDelete() {
      if(this.selection.length===0){
        this.$modal.msg('请选择一条删除数据');
      }else{
        this.modalState = true
        this.modalStatus = 'del'
        this.modalTitle = '提示'
        this.modalWidth = '20%'
      }
    },
    //多选选中
    selectionChange(selection){
      if (selection.length > 1) {
        this.$refs.table.clearSelection()
        this.$refs.table.toggleRowSelection(selection.pop())
      } else {
        this.selection = selection
      }
    }
  }
}
</script>

<style scoped lang="scss">
.rolePermission {
  margin: 15px;

  ::v-deep .el-table__header-wrapper .el-checkbox{
    visibility: hidden;
  }
}
</style>
